<?php

namespace apiend\modules\attach\models;

use Yii;

/**
 * AlbumSearch represents the model behind the search form about [[\app\models\FanasocMemberApply]].
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class AlbumSearch extends \common\models\shop\ShopAttachmentGroup {

    /**
     * @var string 关键字
     */
    public $keyword;

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['keyword'], 'safe'],
        ];
    }

    /**
     * Searching member apply
     * @param  array $params
     * @return \yii\data\ActiveDataProvider
     */
    public function buildQuery() {
        $query = static::find()->alias('t')->active();
        if ($this->keyword) {
            $query->andWhere([
                'or',
                ['like', 't.title', $this->keyword],
                ['like', 't.description', $this->keyword],
            ]);
        }
        $query->andWhere([
            't.store_id' => intval($this->store_id)
        ]);
        $query->debug();
        return $query;
    }

    /**
     * {@inheritdoc}
     */
    public function fields() {
        return [
            'id',
            'title',
            'description',
            'thumb',
            'nums',
            'size' => 'byteSize',
            'reserved',
            'store_id',
            'store',
            'listorder',
        ];
    }

}
